﻿package mortal.game.view.shopMall.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.mvc.core.*;

    public class RebateShopCellRender extends GCellRenderer
    {
        private var _tShopPanicBuyItem:TShopPanicBuyItem;
        private var _shopItem:BaseItem;
        private var _buyLimit:GTextFiled;
        private var _yuanjia:GTextFiled;
        private var _xianjia:GTextFiled;
        private var _propName:GTextFiled;
        private var _oldPrice:GTextFiled;
        private var _leftNum:GTextFiled;
        private var _price:GTextFiled;
        private var _buyBtn:GLoadingButton;
        private var _offBg:GBitmap;
        private var _deleteLine:GBitmap;
        private var _sideIcon:GBitmap;
        private var _listPriceIcon:GBitmap;
        private var _priceIcon:GBitmap;
        private var _discountIcon:GImageBitmap;
        private var _numericStepper:GNumericStepper;
        private var _currentType:int;

        public function RebateShopCellRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:GTextFormat = null;
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(5, 4, 240, 105, this, ImagesConst.GoodsBg));
            _loc_1 = GlobalStyle.textFormatlan.right();
            this._oldPrice = UIFactory.gTextField("", 145, 32, 60, 25, this, _loc_1, true);
            this._price = UIFactory.gTextField("", 145, 80, 60, 25, this, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatBai.center();
            this._yuanjia = UIFactory.gTextField(Language.getString(30060), 85, 32, 60, 25, this, _loc_1, true);
            this._listPriceIcon = UIFactory.gBitmap("", 205, 32, this);
            this._deleteLine = UIFactory.gBitmap(ImagesConst.deleteLine, 174, 37, this);
            this._xianjia = UIFactory.gTextField(Language.getString(30061), 85, 55, 60, 25, this, _loc_1, true);
            this._priceIcon = UIFactory.gBitmap("", 205, 55, this);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.LEFT;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 10, 6, 120, 25, this, _loc_1, true);
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem);
            this._shopItem.x = 11;
            this._shopItem.y = 33;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            this._sideIcon = UIFactory.gBitmap("", 33, 4, this);
            this._buyBtn = UIFactory.gLoadingButton(ResFileConst.ShopMallBuyBtn, 175, 78, 51, 24, this);
            this._buyBtn.drawNow();
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            _loc_1.align = AlignMode.RIGHT;
            _loc_1.bold = false;
            this._numericStepper = UIFactory.gNumericStepper(100, 79, 50, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.value = 1;
            _loc_1 = GlobalStyle.textFormatHong.right();
            _loc_1.size = 15;
            this._buyLimit = UIFactory.gTextField("", 94, 6, 120, 25, this, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatHuang.right();
            _loc_1.size = 14;
            this._leftNum = UIFactory.gTextField("", 24, 78, 60, 30, this, _loc_1, true);
            this._offBg = UIFactory.gBitmap("", 100, 9, this);
            this._discountIcon = UIFactory.gImageBitmap("", 120, 0, this);
            LoaderHelp.addResCallBack(ResFileConst.rebateShop, this.showSkin);
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.resetMaxBuyNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.resetMaxBuyNum);
            this._oldPrice.dispose(param1);
            this._price.dispose(param1);
            this._shopItem.dispose(param1);
            this._buyBtn.dispose(param1);
            this._propName.dispose(param1);
            this._numericStepper.dispose(param1);
            this._sideIcon.dispose(param1);
            this._listPriceIcon.dispose(param1);
            this._priceIcon.dispose(param1);
            this._deleteLine.dispose(param1);
            this._yuanjia.dispose(param1);
            this._xianjia.dispose(param1);
            this._buyLimit.dispose(param1);
            this._leftNum.dispose(param1);
            this._discountIcon.dispose(param1);
            this._oldPrice = null;
            this._price = null;
            this._shopItem = null;
            this._buyBtn = null;
            this._propName = null;
            this._numericStepper = null;
            this._sideIcon = null;
            this._listPriceIcon = null;
            this._priceIcon = null;
            this._deleteLine = null;
            this._yuanjia = null;
            this._xianjia = null;
            this._buyLimit = null;
            this._leftNum = null;
            this._discountIcon = null;
            if (this._offBg)
            {
                this._offBg.dispose(param1);
                this._offBg = null;
            }
            this._tShopPanicBuyItem = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function resetMaxBuyNum(param1:Object = null) : void
        {
            var _loc_2:RebateItemData = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            if (this._tShopPanicBuyItem)
            {
                _loc_2 = Cache.instance.shop.getRebateInfoDicByItemCode(this._tShopPanicBuyItem.itemCode);
                if (_loc_2 && _loc_2.remainInfo)
                {
                    _loc_3 = Cache.instance.role.getMoneyByType(EPriceUnit._EPriceUnitGold);
                    _loc_4 = _loc_2.remainInfo.discount;
                    _loc_5 = _loc_3 / _loc_4;
                    this._numericStepper.maximum = _loc_5 > 999 ? (999) : (_loc_5);
                }
            }
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._offBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.RechargeShopBigOff);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {item:this._shopItem, num:this._numericStepper.value};
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateShopBuyItem, _loc_2));
            return;
        }// end function

        private function setMoneyIcon(param1:int) : void
        {
            var _loc_2:* = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._priceIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._listPriceIcon.bitmapData = _loc_2;
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            if (selected)
            {
                EffectManager.glowFilterReg(this, null, 0.7, 5, 0);
            }
            else
            {
                EffectManager.glowFilterUnReg(this);
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:GTextFormat = null;
            super.data = param1;
            this._tShopPanicBuyItem = param1.data as TShopPanicBuyItem;
            this._shopItem.itemData = new ItemData(this._tShopPanicBuyItem.itemCode);
            this._currentType = param1.type;
            if (this._currentType == 0)
            {
                var _loc_5:Boolean = true;
                this.mouseEnabled = true;
                this.mouseChildren = _loc_5;
                this.filters = [];
            }
            else
            {
                var _loc_5:Boolean = false;
                this.mouseEnabled = false;
                this.mouseChildren = _loc_5;
                this.filters = [FilterConst.colorFilter2];
            }
            var _loc_2:* = int(this._shopItem.itemData.itemInfo.effect / this._shopItem.itemData.itemInfo.effectEx * 100);
            if (_loc_2 >= 66)
            {
                _loc_2 = 66;
            }
            else if (_loc_2 <= 40)
            {
                _loc_2 = 40;
            }
            else
            {
                _loc_2 = 64;
            }
            this._discountIcon.imgUrl = "shopDiscountIcon_" + _loc_2 + ".png";
            this.setMoneyIcon(EPriceUnit._EPriceUnitGold);
            this._numericStepper.value = 1;
            this._oldPrice.text = this._tShopPanicBuyItem.price.toString();
            this._price.y = 55;
            this._xianjia.y = 55;
            this._priceIcon.y = 55;
            _loc_3 = GlobalStyle.textFormatBai.right();
            this._price.defaultTextFormat = _loc_3;
            this._xianjia.text = Language.getString(30061);
            var _loc_4:* = Cache.instance.shop.getRebateInfoDicByItemCode(this._tShopPanicBuyItem.itemCode);
            if (_loc_4 && _loc_4.remainInfo)
            {
                this._price.text = _loc_4.remainInfo.discount.toString();
                if (_loc_4.remainInfo.leftAmount >= 0)
                {
                    this._leftNum.text = Language.getString(35562) + _loc_4.remainInfo.leftAmount.toString();
                }
                else
                {
                    this._leftNum.text = "";
                }
            }
            if (this._tShopPanicBuyItem.buyLimit == 0)
            {
                this._buyLimit.text = "";
                this._offBg.visible = false;
            }
            else
            {
                this._offBg.visible = true;
                if (_loc_4 && _loc_4.playerInfo)
                {
                    this._buyLimit.text = Language.getStringByParam(35563, this._tShopPanicBuyItem.buyLimit - _loc_4.playerInfo.amount, this._tShopPanicBuyItem.buyLimit);
                }
                else
                {
                    this._buyLimit.text = Language.getStringByParam(35563, this._tShopPanicBuyItem.buyLimit, this._tShopPanicBuyItem.buyLimit);
                }
            }
            this._propName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            this.resetMaxBuyNum();
            return;
        }// end function

    }
}
